import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MyCollection<E> {

    private final static int DEFAULT_LENGTH = 10;
    private int size;
    private Object[] e;

    public MyCollection() {
        this.e = new Object[DEFAULT_LENGTH];
    }

    public MyCollection(int length) {
        this.e = new Object[length];
    }

    public void add(E obj) {
        if (size == e.length) {
            int new_length = e.length + (e.length >> 1);
            e = Arrays.copyOf(e, new_length);
        }
        e[size++] = obj;
    }

    public int size() {
        return this.size;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < size; i++) {
            sb.append(e[i] + ",");
        }
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}


class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        MyCollection<String> collection = new MyCollection<>(15);
        for (int i = 0; i < 5; i++) {
            collection.add("hello" + i);
        }
        System.out.println(collection.size());
        System.out.println(collection.toString());
    }
}
